<template>
  <div class="fs-tabbar">
    <div class="fs-tabbar-container">
      <div
        :class="['tab-item', currentIndex === index ? 'tab-item-active' : '']"
        v-for="(item, index) in routes"
        :key="index"
        @click="handleSkipToPage(item.name)"
      >
        <van-icon :name="item.icon" class="tab-item-icon" />
        <div class="tab-item-title">{{ item.title }}</div>
      </div>
      <div class="tab-item-user" @click="$router.push('/me')">
        <div class="user-item">
          <van-icon name="user-o" class="tab-item-icon" />
          <div class="tab-item-title">关于</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { useRouter, useRoute } from "vue-router";
const $route = useRoute(),
  $router = useRouter();
const handleSkipToPage = (path: string) => {
  $router.push(path);
};

const currentIndex = computed(() => routes.map((item) => item.name).indexOf($route.path));

const routes = [
  {
    name: "/",
    icon: "home-o",
    title: "首页",
  },
  {
    name: "/music",
    icon: "music-o",
    title: "音乐",
  },
  {
    name: "/game",
    icon: "aim",
    title: "游戏",
  },
  {
    name: "/pixiv",
    icon: "flower-o",
    title: "插画",
  },
  // {
  //   name: "/me",
  //   icon: "user-o",
  //   title: "我的",
  // },
];
</script>

<style scoped lang="scss">
.fs-tabbar {
  position: fixed;
  bottom: 0;
  z-index: 999;
  width: 100%;
  height: 65px;
  box-shadow: 0 -1px 10px rgba(0, 0, 0, 0.1);
  background-color: var(--nav-color);
  color: var(--font-light-color);
  &-container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .tab-item {
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100%;
      flex: 1;
      font-size: 15px;
      &-icon {
        font-size: 25px;
        margin-bottom: 5px;
      }
      &-active {
        color: #fff;
        &::before {
          transform: rotate(0) !important;
          opacity: 1 !important;
        }
      }

      &::before {
        position: absolute;
        content: "";
        top: 10%;
        left: 10%;
        width: 80%;
        height: 80%;
        background-color: var(--remind-color);
        border-radius: 12px;
        z-index: -1;
        opacity: 1;
        transform: rotate(-180deg);
        transform-origin: bottom left;
        transition: all 0.5s ease-in-out;
        opacity: 0;
      }
    }

    .tab-item-user {
      margin-left: 10px;
      width: 100px;
      height: 80px;
      background: #e5707e;
      border-top-left-radius: 34px;
      box-shadow: 0 0 15px #e5707e;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      .user-item {
        display: flex;
        flex-direction: column;
        align-items: center;
      }
    }
  }
}
</style>
